package com.xjm.ips.controller.salary;

import com.xjm.ips.entity.AjaxJson;
import com.xjm.ips.entity.MyPage;
import com.xjm.ips.entity.SettleSalary;
import com.xjm.ips.service.SettleSalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/salary/month")
public class SalaryMonthController {
    @Autowired
    SettleSalaryService settleSalaryService;

    @GetMapping("/")
    public MyPage getAllSettleSalariesForSearch(@RequestParam(defaultValue = "1") Integer pageNo,
                                       @RequestParam(defaultValue = "10") Integer pageSize,
                                       SettleSalary settleSalary){
        return settleSalaryService.getAllSettleSalariesForSearch(pageNo,pageSize,settleSalary);
    }

    @PostMapping("/addmonthsalaries")
    public AjaxJson addMonthSalaries(@RequestBody List<SettleSalary> settleSalaryList){
        if(settleSalaryService.addMonthSalaries(settleSalaryList)==settleSalaryList.size()){
            return AjaxJson.ok("批量处理工资单成功!");
        }
        return AjaxJson.error("批量处理工资单失败!");
    }

    @GetMapping("/monthsalaries")
    public MyPage getAllSettleSalaries(@RequestParam(defaultValue = "1") Integer pageNo,
                                       @RequestParam(defaultValue = "10") Integer pageSize,
                                       SettleSalary settleSalary){
        return settleSalaryService.getAllSettleSalaries(pageNo,pageSize,settleSalary);
    }

    @DeleteMapping("/{id}")
    public AjaxJson deleteSalaryMonthById(@PathVariable Integer id){
        if(settleSalaryService.deleteSalaryMonthById(id)==1){
            return AjaxJson.ok("撤销工资单成功!");
        }
        return AjaxJson.error("撤销工资单失败!");
    }

}
